﻿//共享onload事件
function addLoadFuc(func) {
    var oldLoad = window.onload;
    if (typeof(window.onload) != 'function') {
        window.onload = func;
    } else
        window.onload = function() {
            oldLoad();
            func();
        };
}

//添加和移除事件
var EventUtil = {
    addHandler: function(element, type, handler) {
        if (element.addEventListener) {
            element.addEventListener(type, handler, false);
        } else if (element.attachEvent) {
            element.attachEvent("on" + type, handler);
        } else {
            element["on" + type] = handler;
        }
    },
    revmoveHandler: function(element, type, handler) {
        if (element.removeEventListener) {
            element.removeEventListener(type, handler, false);
        } else if (element.detachEvent) {
            element.detachEvent("on" + type, handler);
        } else {
            element["on" + type] = null;
        }
    }
};
// 获取地址栏的参数数组

function getUrlParams() {
    var search = window.location.search;
    // 写入数据字典
    var tmparray = search.substr(1, search.length).split("&");
    var paramsArray = new Array;
    if (tmparray != null) {
        for (var i = 0; i < tmparray.length; i++) {
            var reg = /[=|^==]/; // 用=进行拆分，但不包括==
            var set1 = tmparray[i].replace(reg, '&');
            var tmpStr2 = set1.split('&');
            var array = new Array;
            array[tmpStr2[0]] = tmpStr2[1];
            paramsArray.push(array);
        }
    }
    // 将参数数组进行返回
    return paramsArray;
}

// 根据参数名称获取参数值

function getParamValue(name) {
    var paramsArray = getUrlParams();
    if (paramsArray != null) {
        for (var i = 0; i < paramsArray.length; i++) {
            for (var j in paramsArray[i]) {
                if (j == name) {
                    return paramsArray[i][j];
                }
            }
        }
    }
    return null;
}

/*--------------------------------select----------------------------------start-----------*/
//获取select值

function $id(parameters) {
    return document.getElementById(parameters);
}
function getSelectItem(selname) {
    var sel = $id(selname);
    if (sel) return sel.options[sel.selectedIndex == undefined ? 0 : sel.selectedIndex];
    return undefined;
}

//添加option到select中

function addOptionToSelect(sel, value, text) {
    sel.options.add(new Option(text, value));
}

//--删除selet中所有选项

function delAllOptions(sel) {
    document.getElementById(sel).options.length = 0;
}
/*--------------------------------select-----------------------------------end-----------*/